<?php


namespace App\Model;


use Illuminate\Database\Eloquent\Model;

class Refund extends Model
{
    const CREATED_AT = 'createtime';
    const UPDATED_AT = 'updatetime';

    //表名
    protected $table = 'refund';

    // 追加属性
    protected $appends = [
        'refund_type_text',
        'status_text'
    ];

    public function getGoodsPriceAttribute($value)
    {
        return bcdiv($value, 100, 2);
    }

    protected function setGoodsPriceAttribute($value)
    {
        return bcmul($value, 100, 0);
    }

    public function getRefundPriceAttribute($value)
    {
        return bcdiv($value, 100, 2);
    }

    protected function setRefundPriceAttribute($value)
    {
        return bcmul($value, 100, 0);
    }

    public function getRefundTypeTextAttribute()
    {
        $value = $this->refund_type;
        $list = $this->getRefundTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getStatusTextAttribute()
    {
        $value = $this->status;
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRefundTypeList()
    {
        return [1 => '退款', 2 => '退货退款', 3 => '换货'];
    }

    public function getStatusList()
    {
        return [1 => '审核中', 2 => '已通过', 3 => '已拒绝', 4 => '已取消', 5 => '回寄中', 6 => '已回寄', 7 => '已退款'];
    }

    /**
     * 关联订单表
     */
    public function order()
    {
        return $this->belongsTo('App\Model\Order', 'order_id', 'id', '')->select('id', 'order_sn');
    }
}
